package com.example.administrator.caigou51.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;

import com.alibaba.fastjson.JSON;
import com.example.administrator.caigou51.R;
import com.example.administrator.caigou51.bean.MainDataBean;
import com.example.administrator.caigou51.bean.TradeBean;
import com.example.administrator.caigou51.global.Constant;
import com.example.administrator.caigou51.recyclerCard.basic.MaterialListView;
import com.example.administrator.caigou51.recyclerCard.card.MainPart3Card;
import com.example.administrator.caigou51.recyclerCard.card.TradeSuccess1Card;
import com.example.administrator.caigou51.request.BaseResponse;
import com.example.administrator.caigou51.request.ICallBackForRequestServer;
import com.example.administrator.caigou51.request.RequestServerManager;

/**
 * Created by Administrator on 2016/9/1/001.
 */
public class TradeSuccessActivity extends GBaseActivity {
    MaterialListView materialListView;
    MainDataBean mainDataBean;
    public static String TagPayStyle="TagPayStyle" ;
    public static String TagPayTotal="TagPayTotal" ;
    public static String TagPayTips="TagPayTips" ;
    public String payTotal;
    public String payStyle;
    public String payTips;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentViewFor720_1280(R.layout.template_materiallistview_layout);
        findViewByIds();
        initDatas();
        TaskGetMainData(false);
    }


    protected void findViewByIds() {
        materialListView= (MaterialListView) findViewById(R.id.material_listview);
    }


    protected void initDatas() {
        setTopTitle("交易成功");
        payTotal=getIntent().getStringExtra(TagPayTotal);
        payStyle=getIntent().getStringExtra(TagPayStyle);
        payTips=getIntent().getStringExtra(TagPayTips);
    }

    protected void fillArrayInListView(MainDataBean userBean) {
        TradeSuccess1Card tradeSuccess1Card=new TradeSuccess1Card(this);
        tradeSuccess1Card.setPayStyle(payStyle);
        tradeSuccess1Card.setPayTotal(payTotal);
        tradeSuccess1Card.setPayTips(payTips);
        materialListView.add(tradeSuccess1Card);


        for (int i=0;i<mainDataBean.getHotsell().size();i=i+2)
        {

            MainPart3Card mainPart3Card = new MainPart3Card(getActivity());
            mainPart3Card.setMainDataBean(mainDataBean);
            mainPart3Card.setIndex(i);
            mainPart3Card.setTradeFromSuccess(true);
            materialListView.add(mainPart3Card);

        }
      /*  MainPart3Card mainPart3Card =new MainPart3Card(this);
        materialListView.add(mainPart3Card);

        MainPart3Card mainPart3Card2 =new MainPart3Card(this);
        materialListView.add(mainPart3Card2);*/
    }
    private void TaskGetMainData(final boolean isloadmore) {
        RequestServerManager.getInstanceDIY().handleMethodDIY((GBaseActivity) getActivity(), materialListView, isloadmore, null,
                Constant.getRootUrl() + Constant.Action.Action_MainData, Constant.Action.TokenAct_MainData, RequestServerManager.getInstanceDIY().
                        getRequestParams(Constant.Action.Action_MainData,"1000", "1"), BaseResponse.class, new ICallBackForRequestServer<BaseResponse>() {
                    @Override
                    public void onSuccess(BaseResponse result) {
                        // JSONObject jsonObject = (JSONObject) result.getData();
                        mainDataBean = JSON.parseObject(result.getData().toString(), MainDataBean.class);
                        fillArrayInListView(mainDataBean);
                    }

                    @Override
                    public void onFail(int type, String errorMsg, String json) {

                    }
                });
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        Intent intent=new Intent(this, MainActivity.class);
        startActivity(intent);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Intent intent=new Intent(this, MainActivity.class);
        startActivity(intent);
    }
}
